package cn.jsony.basic.service.impl;

import cn.jsony.basic.config.BusinessException;
import cn.jsony.basic.service.IBaiduAiAuditService;
import cn.jsony.basic.util.BaiduAiUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class BaiduAiAuditServiceImpl implements IBaiduAiAuditService {
    @Override
    public Boolean textAudit(String text) {
        //文字审核
        if (!BaiduAiUtils.textCensor(text)){
            throw new BusinessException("名字不合规");
        }
        return true;

    }

    @Override
    public Boolean imageAudit(String resources) {
        //3.1图片审核
        /*
         *  注意:resources是这样的格式：
         *  /group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk161.png,/group1/M00/00/02/CgAIC2KevEeAX2T4AAEUusLjqqk162.png
         *  需要判断是否为空，只有一张怎么处理，有多张怎么处理
         *  需要统一加前缀：http://123.207.27.208
         */
        if (!StringUtils.isEmpty(resources)) {
            String[] resourcesArrs = resources.split(",");
            for (String resourcesArr : resourcesArrs) {
                String imgUrl = "http://123.207.27.208"+resourcesArr;
                if (!BaiduAiUtils.imgCensor(imgUrl)){
                    throw new BusinessException("图片不合规");
                }
            }

        }
        return true;
    }
}
